﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;

namespace JinianNet.Data
{
    public class Transaction
    {
        public CommandType CommandType { get; set; }
        public string Text { get; set; }
        public DbParameter[] Parameter { get; set; }
    }

    public class TransactionCollection : List<Transaction>
    {
        public TransactionCollection()
            : base()
        {
        }

        public TransactionCollection(int capacity)
            : base(capacity)
        {
        }

        public TransactionCollection(IEnumerable<Transaction> collection)
            : base(collection)
        {

        }

        public TransactionCollection(string[] collection)
            : this(collection.Length)
        {
            this.AddRange(collection);
        }

        public void Add(string item)
        {
            this.Add(new Transaction() { 
                CommandType = CommandType.Text,
                Text = item,
                Parameter = null
            });
        }

        public void Add(CommandType commandType,string cmdText)
        {
            this.Add(new Transaction()
            {
                CommandType = commandType,
                Text = cmdText,
                Parameter = null
            }); 
        }

        public void AddRange(string[] collection)
        {
            for (int i = 0; i < collection.Length; i++)
            {
                if (!string.IsNullOrEmpty(collection[i]))
                {
                    this.Add(collection[i]);
                }
            } 
        }
    }

}
